package com.nineclock.approve.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nineclock.approve.dto.ApproveInstDTO;
import com.nineclock.approve.mapper.ApproveInstMapper;
import com.nineclock.approve.pojo.ApproveInst;
import com.nineclock.approve.service.ApproveInstService;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.utils.BeanHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class ApproveInstServiceImpl implements ApproveInstService {

    @Autowired
    private ApproveInstMapper approveInstMapper;

    /**
     * 分页查询审批列表
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public PageResult<ApproveInstDTO> queryApproveInst(Integer page, Integer pageSize) {

        IPage<ApproveInst> ipage=new Page<>(page,pageSize);
       ipage= approveInstMapper.selectPage(ipage,null);

        List<ApproveInst> approveInsts = ipage.getRecords();

        if (!CollectionUtils.isEmpty(approveInsts)){
      List<ApproveInstDTO> approveInstDTOS = BeanHelper.copyWithCollection(approveInsts, ApproveInstDTO.class);


            return new PageResult<>(ipage.getTotal(),ipage.getPages(),approveInstDTOS);

        }

        return null;
    }
}
